package cn.itcast.order.service;

import cn.itcast.order.client.UserClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        // 2、远程调用，查询user
        /*String url = "http://user-service/user/" + order.getUserId();
        User user = restTemplate.getForObject(url, User.class);*/
        User user = userClient.queryById(order.getUserId());
        // 3、放近order
        order.setUser(user);
        // 4.返回
        return order;
    }

    @SentinelResource("goods")
    public String getGoods(){
        System.err.println("一些货品");
        return "一些货品";
    }
}
